package com.hubu.controller;


import com.hubu.common.lang.R;
import com.hubu.entity.HldQuestion;
import com.hubu.entity.HldTestResult;
import com.hubu.entity.vo.HldResultVO;
import com.hubu.service.HldQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Hubu
 * @since 2021-11-18
 */
@RestController
@RequestMapping("/hld-question")
public class HldQuestionController {
    @Autowired
    HldQuestionService hldQuestionService;

    @GetMapping("get/{id}")
    public R getHldQuestion(@PathVariable String id) {
        HldQuestion hldQuestion = hldQuestionService.getById(id);
        return R.ok().data("data", hldQuestion);
    }

    @PostMapping("/submit")
    public R submitHldTest(@RequestBody HldResultVO hldResultVO) {
        Map<String, Object> hldTestResult = hldQuestionService.submitHldTest(hldResultVO);
        return R.ok().data("data", hldTestResult);
    }

    @GetMapping("/ques")
    public R getAllQuestions() {
        List<HldQuestion> list = hldQuestionService.list();
        Map<String, Object> map = new HashMap<>();
        map.put("total", list.size());
        map.put("records ", list);
        return R.ok().data("data", map);
    }

}
